#! /usr/bin/bash

# mkbeta.sh: start a new beta test. 

beta="betatest-`date +\"%Y.%m.%d\"`"
echo "starting beta test: $beta"

echo -n "# " > $beta 
date >> $beta

vim .test.trp

echo -en "\033[1;36;40m"
echo "Running: "
echo -en "\033[0m"

cat .test.trp >> $beta

if [ ! -s .test.trp ]; then 
	echo -ne "\033[1;31;40m"
	echo "*** NO CODE TO RUN"
	echo -ne "\033[0m"

	exit 1
fi

rm -f .test.trp 

# and run

make > /dev/null 

rm -f .errmsg .stdout 

./tripl $beta >& .errmsg > .stdout 

if [ ! -s .errmsg ]; then
	echo -en "\033[1;32;40m"
	echo "OK"
	echo -en "\033[0m"
	echo "Test finished successfully\n"

	echo "Output: "
	cat .stdout 

else
	echo -ne "\033[1;31;40m"
	echo "Oops! :-("
	echo -ne "\033[0m"
	echo "error message: "
	cat .errmsg

	echo "Debugging $beta"
	gdb ./tripl  
fi

rm -f .errmsg .stdout 

